Skip to content

fix(facets): export label and count columns in facet CSV download#864

Open
thostetler wants to merge 3 commits intoadsabs:masterfrom
thostetler:SCIX-872-facet-csv-export
Open

fix(facets): export label and count columns in facet CSV download#864
thostetler wants to merge 3 commits intoadsabs:masterfrom
thostetler:SCIX-872-facet-csv-export

Conversation

@thostetler
Copy link
Copy Markdown
Member

@thostetler thostetler commented May 8, 2026

Facet modal download only exported the label column — the count was never included it seems?

  • Extracts formatFacetCSV as a pure helper that emits a proper two-column CSV (Label,Count)
  • Updates FacetDownloadButton to use the helper; changes filename to fulllist.csv and MIME type to text/csv
  • Adds unit tests

Closes SCIX-872

@thostetler
Copy link
Copy Markdown
Member Author

@shinyichen should this one be CSV?
I just noticed that these output as txt

Let me know if these changes makes sense. Thanks!

@thostetler thostetler marked this pull request as ready for review May 8, 2026 21:12
@thostetler thostetler requested review from Copilot and shinyichen May 8, 2026 21:12
@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.7%. Comparing base (5a4245b) to head (7c61da0).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #864     +/-   ##
========================================
+ Coverage    62.7%   62.7%   +0.1%     
========================================
  Files         323     323             
  Lines       38011   38029     +18     
  Branches     1723    1724      +1     
========================================
+ Hits        23802   23821     +19     
+ Misses      14169   14168      -1     
  Partials       40      40             
Files with missing lines Coverage Δ
src/components/SearchFacet/helpers.ts 59.4% <100.0%> (+2.8%) ⬆️
src/lib/useDownloadFile.ts 91.5% <100.0%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Risk summary: Medium risk — behavior is straightforward (CSV formatting + download), but the intended CSV MIME type is not actually applied due to how useDownloadFile constructs the Blob.

Changes:

  • Added a pure formatFacetCSV helper to export facet data as Label,Count CSV with basic RFC-style escaping.
  • Updated facet modal download to use CSV output and a .csv filename.
  • Added unit tests covering CSV formatting behavior and escaping.

Findings (priority order)

  • medium — Incorrect MIME type for CSV download (bug)
    • Impact: Downloaded file may not be recognized/handled as CSV by browsers/OS tooling (despite .csv extension), contradicting the PR’s stated goal of setting text/csv.
    • Location: src/components/SearchFacet/SearchFacetModal/SearchFacetModal.tsx:202-203
    • Minimal fix: Update useDownloadFile to use the MIME returned by getMetaData(type) when creating the Blob (instead of passing the FileType string as the Blob type), or otherwise allow passing an explicit MIME type.
    • Confidence: high

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/components/SearchFacet/SearchFacetModal/SearchFacetModal.tsx Switches facet full-list download to CSV output via shared helper and .csv filename.
src/components/SearchFacet/helpers.ts Adds formatFacetCSV(items) helper to generate Label,Count CSV with escaping.
src/components/SearchFacet/tests/helpers.test.ts Adds unit tests for formatFacetCSV (header, hierarchy stripping, counts, escaping).

Comment on lines +202 to +203
const formatData = useCallback(() => formatFacetCSV(treeData), [treeData]);
const { onDownload } = useDownloadFile(formatData, { filename: 'fulllist.csv', type: 'CSV' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants